package com.yft.dao.purchasepos;

import com.yft.dao.base.BaseConstant;
import com.yft.dao.base.BaseDao;
import com.yft.entity.base.BaseEntityUtils;
import com.yft.entity.base.Order;
import com.yft.entity.base.Pager;
import com.yft.entity.purchasepos.PosPurchaseOrderDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;


@Service("posPurchaseOrderDetailDao")
public class PosPurchaseOrderDetailDao {
	
	@Autowired(required = true)
	@Qualifier(BaseConstant.DAO_NAME)
	private BaseDao dao;
	
	public Object addPosPurchaseOrderDetail(PosPurchaseOrderDetail posPurchaseOrderDetail) {
		return dao.addEntity(posPurchaseOrderDetail);
	}

    public boolean saveAllPosPurchaseOrderDetails(List<PosPurchaseOrderDetail> posPurchaseOrderDetails) {
        return dao.saveAllEntity(posPurchaseOrderDetails);
    }
	
	public PosPurchaseOrderDetail getPosPurchaseOrderDetail(Object posPurchaseOrderDetailPK){
		return (PosPurchaseOrderDetail)dao.getEntity(PosPurchaseOrderDetail.class,(Serializable)posPurchaseOrderDetailPK);
	}

    public boolean delPosPurchaseOrderDetail(Object posPurchaseOrderDetail){
        return dao.deleteEntityByObject(posPurchaseOrderDetail);
    }
	

	public boolean updateValues(PosPurchaseOrderDetail condition,String customStr){
		return dao.updateValues(condition, customStr);
	}
	
	@SuppressWarnings("unchecked")
	public List<PosPurchaseOrderDetail> getPosPurchaseOrderDetailList(PosPurchaseOrderDetail condition, Order order,Pager pager){
		return getList("",condition,order,pager);
	}	
	
	@SuppressWarnings("unchecked")
	private List getList(String hql,PosPurchaseOrderDetail condition,Order order,Pager pager){
		
		String q = hql+"from PosPurchaseOrderDetail c  where 1=1 ";
		q += makeCondition(condition);
		q += order!=null? order.toString():"";
		
		return dao.getListPager(q,condition,pager);
		
	}
	
	public String makeCondition(PosPurchaseOrderDetail condition){
		condition = condition==null? new PosPurchaseOrderDetail():condition;
		
		String q = "";
		q += BaseEntityUtils.makeBaseCondition(condition);
		
		return q;
	}
}
